/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.gss
import org.gss.styles.*

/**
 *
 * @author btilford
 */
class Bootstrap {
    
    static void boot() {
	String.metaClass.css = {params->
	    params.name = delegate
	    new Rule(params)
	}
	Number.metaClass.getPx = {
	    new NumericValue(value:delegate,unit:Unit.px)
	}
	Number.metaClass.getPercent = {
	    new NumericValue(value:delegate,unit:Unit.percent)
	}
	Number.metaClass.getEm = {
	    new NumericValue(value:delegate,unit:Unit.em)
	}


	Object.metaClass.rgb = {Integer red, Integer green,Integer blue->
	    new RGBValue(red:red,green:green,blue:blue)
	}
	Object.metaClass.rgba = {Integer red, Integer green,Integer blue,Float alpha->
	    new RGBValue(red:red,green:green,blue:blue,alpha:alpha)
	}
	Object.metaClass.hex = {String hexString->
	    Value value = null
	    if(!hexString.startsWith("#")) {
		hexString = "#$hexString"
	    }
	    if(hexString.size() == 7) {
		value = new ColorStringValue(value:hexString)
	    } else {
		throw new Exception("$hexString is not an hex value!")
	    }
	    return value
	}
	Object.metaClass.octal = {String octalString->
	    Value value = null
	    if(!octalString.startsWith("#")) {
		octalString = "#$octalString"
	    }
	    if(octalString.size() == 4) {
		value = new ColorStringValue(value:octalString)
	    } else {
		throw new Exception("$octalString is not an octal value!")
	    }
	    return value
	}

	
	Object.metaClass.border = {NumericValue size,String style,ColorValue color->
	    new BorderDeclaration(
		value:new BorderValue(
		    size:size,
		    style:new TextValue(text:style),
		    color:color
		)
	    )
	}
    }
}

